#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;

        int next = 0;
        string ret;
        while (end1 >= 0 || end2 >= 0)
        {

            int val1 = end1 >= 0 ? num1[end1--] - '0' : 0;
            int val2 = end2 >= 0 ? num2[end2--] - '0' : 0;
            int val = val1 + val2 + next;
            next = val / 10;
            val = val % 10;
            ret.push_back(val + '0');

        }
        if (next == 1)
        {
            ret.push_back('1');
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};